package com.fhz.day007.delagate

/**
 * 时间:2021/10/21
 * @author msfeng
 * 简述: TODO
 */
fun main(){

    val mySet = MySet<Int>(HashSet())
    mySet.add(1)
    mySet.add(2)
    mySet.add(4)

    println(mySet.size)
//    mySet.contains(1)

    val hashSet = HashSet<Int>()
    hashSet.add(1)
    hashSet.add(2)
    hashSet.add(3)
    hashSet.add(4)

}

class MySet<T>(var helperSet: HashSet<T>) : Set<T>{
    override val size: Int
        get() = helperSet.size

    fun add(t:T){
        if(t as Int > 3){
            helperSet.add(t)
        }
    }

    override fun contains(element: T) = helperSet.contains(element)

    override fun containsAll(elements: Collection<T>) = helperSet.containsAll(elements)

    override fun isEmpty() = helperSet.isEmpty()

    override fun iterator() = helperSet.iterator()


}


